const Router = require('koa-router');
const Article = require('../../model/Article');

const router = new Router({
  prefix: `/api/v1`
});

router.get('/article', async (ctx, next) => {
  const {order_by, page_number, userid} = ctx.request.query;
  const res = await Article.getArticlesByPageNumber({
    order_by
    , page_number
    , filter: userid ? {UserId: userid} : {}
  });
  helper.success(res);
});

router.get('/article/:id', async (ctx, next) => {
  const id = ctx.params.id;
  const res = await Article.getArticleDetailById(parseInt(id));
  helper.success(res);
});

//TODO 根据tag、搜索词 来 获取文章列表 [post] /article
router.post('/article/search', async (ctx, next) => {
  helper.success([]);
});

module.exports = router;
